//
//  ViewController.m
//  scrollView Practise
//
//  Created by student on 16/2/29.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIPageControl *pagecontrol;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIImageView *image1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 400, 140)];
    image1.image = [UIImage imageNamed:@"1"];
    UIImageView *image2 = [[UIImageView alloc]initWithFrame:CGRectMake(415, 0, 400, 140)];
    image2.image = [UIImage imageNamed:@"2"];

    UIImageView *image3 = [[UIImageView alloc]initWithFrame:CGRectMake(415*2, 0, 400, 140)];
    image3.image = [UIImage imageNamed:@"3"];

    UIImageView *image4 = [[UIImageView alloc]initWithFrame:CGRectMake(415*3, 0, 400, 140)];
    image4.image = [UIImage imageNamed:@"4"];

    UIImageView *image5 = [[UIImageView alloc]initWithFrame:CGRectMake(415*4, 0, 400, 140)];
    image5.image = [UIImage imageNamed:@"5"];

    UIImageView *image6 = [[UIImageView alloc]initWithFrame:CGRectMake(415*5, 0, 400, 140)];
    image6.image = [UIImage imageNamed:@"6"];

    UIScrollView *scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 200, 400, 140)];
    [scrollview addSubview:image1];
    [scrollview addSubview:image2];
    [scrollview addSubview:image3];
    [scrollview addSubview:image4];
    [scrollview addSubview:image5];
    [scrollview addSubview:image6];
    scrollview.contentSize = CGSizeMake(415*6, 140);
    scrollview.bounces = YES;
    // 3. 滑动条样式
    scrollview.indicatorStyle = UIScrollViewIndicatorStyleWhite;

    [self.view addSubview:scrollview];
    scrollview.pagingEnabled = YES;
    scrollview.delegate = self;
    
    // 设置pageControl
    [self.view addSubview:self.pagecontrol];// 将拖入的分页控件前置到最前
    // 1. 总共有几页内容
    self.pagecontrol.numberOfPages = 6;
    self.pagecontrol.currentPage = 0;
    self.pagecontrol.pageIndicatorTintColor = [UIColor yellowColor];
    self.pagecontrol.currentPageIndicatorTintColor= [UIColor redColor];
    // Do any additional setup after loading the view, typically from a nib.
    
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSLog(@"%s",__func__);
    // 根据当前内容偏移的位置,计算当前是第几页
    // 内容偏移:contentOffset
    self.pagecontrol.currentPage = scrollView.contentOffset.x/250;
}


@end
